import { Injectable } from '@angular/core';
// 登录守卫函数 
import {
    CanActivate, ActivatedRoute, Router,
    ActivatedRouteSnapshot, RouterStateSnapshot,
} from '@angular/router';


@Injectable()
export class LoginGuard implements CanActivate {

    constructor(
        private router: Router,          //跳转
    ) {

    }
    // 实现接口方法  进入这个路由时候的守卫函数
    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        let loggedIn: boolean = true

        // 没登陆跳转到login页面去
        if (!loggedIn) {
            this.router.navigate([`/login`])
        }
        return loggedIn
    }
}